<? 
include 'header.php'; 
?>
<h1><?= isset($edit) ? 'Update' : 'Add' ?> Product</h1>

<?= isset($message) && !empty($message) ? '<div id="alert">' . $message . '</div>' : '' ?>

<!-- the form :) -->
<form action="<?= base_url() ?>index.php/admin/product/processadd" method="POST">

<div id="selectcategories">
    <strong>Categories</strong> <a class='addcat' onclick='return false' id='addcat_top'>(+)</a><br />
    <div id="addcatform_top" class="addcatform">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>
    <div id="addcatshere_top"></div>
    <?
    foreach($categories as $category) {
        if ($category->parentid != "99") {
            if ($category->catid != "99") {
                echo $category->tabs . "<input type='checkbox' id='category[" . $category->catid . "]'";
                if (isset($edit->categories) && in_array($category->catid, $edit->categories)) {
                    echo " checked ";
                }
                echo " name='category[" . $category->catid . "]' value='" . $category->catid . "' /><label for='category[" . $category->catid . "]'>" . $category->catname . "</label> <a onclick='return false' class='addcat' id='addcat_" . $category->catid . "'>(+)</a><br />";
            } else {
                echo $category->tabs . "<input type='checkbox' disabled /><b><u>" . $category->catname . "</u></b><br />";
                
            }
                
            echo '<div id="addcatform_' . $category->catid . '" class="addcatform">' . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . $category->tabs . '</div>';
            echo '<div id="addcatshere_' . $category->catid . '"></div>';
        } else {
            echo $category->tabs . "<input type='checkbox' id='category[" . $category->catid . "]'";
            if (isset($edit->categories) && in_array($category->catid, $edit->categories)) {
                    echo " checked ";
            } 
            echo " name='category[" . $category->catid . "]' value='" . $category->catid . "' /><label for='category[" . $category->catid . "]'><em><b>" . $category->catname . "</b></em></label><br />";
        }
     } ?>
</div>


<div id="addproductform">
    Product Title: <input id="title" name="title" value="<?= isset($edit->title) ? $edit->title : '' ?>" /><br />
    Universal Product Code (UPC): <input id="upc" name="upc" value="<?= isset($edit->upc) ? $edit->upc : '' ?>" /><br />
    Store Keeping Unit (SKU): <input id="sku" name="sku" value="<?= isset($edit->sku) ? $edit->sku : '' ?>" /><br />
    Price: $<input id="price" name="price" value="<?= isset($edit->price) ? $edit->price : '' ?>" />
    &nbsp;&nbsp;&nbsp;
 Product Visibility: <select name="invisible">
                <option value="false" <?= isset($edit->invisible) && $edit->invisible == '0' ? 'selected="yes"' : '' ?>>Visible</option>
                <option value="true" <?= isset($edit->invisible) && $edit->invisible == '1' ? 'selected="yes"' : '' ?>>Invisible</option>
                </select>
    
    <br />
    
    <p>
        Description: <br />
        <textarea id="description" name="description"><?= isset($edit->description) ? $edit->description : '' ?></textarea>
    </p>


    Media: <br /><?php echo form_open_multipart('upload/do_upload');?>
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="50000"><input type="file" id="imgfile" name="userfile">
<input type="button" id="uploadimage" onclick="return false" value="Upload Image">
</form><br />
    
    <div id="media">
        <?php if ( isset($edit) && !empty($edit->image) ) {
            $images = explode(',', $edit->image);
            
            foreach ($images as $image) {
                ?>
                <img src="<?=$image?>" class="picture" />
                <?
            }
        }
        
        ?>
    </div><br />
    
   
    <input type="submit" id="submitadd" value="<?= isset($edit) ? 'Update Product' : 'Add Product'?>" /> <?= isset($edit) ? '' : '<input type="reset" value="Cancel" />' ?>
    
</div>


</form>

<?php
include 'footer.php';
?>